home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / adx7mu1a / connectf.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-10-07  |  3.9 KB  |  133 lines

  1. VERSION 5.00
  2. Begin VB.Form connectfrm 
  3.    Caption         =   "Choose Connection Type"
  4.    ClientHeight    =   3720
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   7860
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3720
  10.    ScaleWidth      =   7860
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton cmdok 
  13.       Caption         =   "Connect"
  14.       Height          =   615
  15.       Left            =   6000
  16.       TabIndex        =   3
  17.       Top             =   2880
  18.       Width           =   1575
  19.    End
  20.    Begin VB.ListBox connectiontype 
  21.       Height          =   2010
  22.       Left            =   480
  23.       TabIndex        =   2
  24.       Top             =   240
  25.       Width           =   4935
  26.    End
  27.    Begin VB.TextBox PlayersName 
  28.       Height          =   495
  29.       Left            =   720
  30.       TabIndex        =   0
  31.       Text            =   "Text1"
  32.       Top             =   3000
  33.       Width           =   4335
  34.    End
  35.    Begin VB.Label Label1 
  36.       Caption         =   "Players Name."
  37.       Height          =   255
  38.       Left            =   720
  39.       TabIndex        =   1
  40.       Top             =   2760
  41.       Width           =   3855
  42.    End
  43. Attribute VB_Name = "connectfrm"
  44. Attribute VB_GlobalNameSpace = False
  45. Attribute VB_Creatable = False
  46. Attribute VB_PredeclaredId = True
  47. Attribute VB_Exposed = False
  48. Option Explicit
  49. Private Sub cmdCancel_Click()
  50.   ' Force initialization of DirectPlay if user comes back in
  51.   Unload Me
  52.   'frmMainMenu.Show
  53. End Sub
  54. Private Sub cmdOK_Click()
  55.   Dim cindex As Long
  56.   Dim ConnectionMade As Boolean
  57.   Dim dxAddress As DirectPlayAddress
  58.   ' Initialize the connection. Any service provider dialogs are not called till the
  59.   ' connection is used, e.g. to enumerate sessions.
  60.   cindex = connectiontype.ListIndex + 1
  61.   On Error GoTo INITIALIZEFAILED
  62.   usermode = "host"
  63.   If usermode = "host" Then
  64.    Hide
  65.    Lobby.Show
  66.    Exit Sub
  67.   Else
  68.    Set dxAddress = EnumConnections.GetAddress(cindex)
  69.   Call dxplay.InitializeConnection(dxAddress)
  70.   End If
  71.   On Error GoTo 0
  72.   ' Enumerate the sessions to be shown in the SessionForm listbox. If this fails with
  73.   ' DPERR_USERCANCEL, the user cancelled out of a service provider dialog. This is
  74.   ' not a fatal error, because for the modem connection it simply indicates the
  75.   ' player wishes to host a session and not to make a dial-up connection. The "answer"
  76.   ' dialog will come up when the user attempts to create a session.
  77.   ConnectionMade = Lobby.UpdateSessionList
  78.   If ConnectionMade Then
  79.     Hide
  80.     Lobby.Show
  81.   Else
  82.     InitDPlay
  83.   End If
  84.   Exit Sub
  85.   ' Error handlers
  86. INITIALIZEFAILED:
  87.   If Err.Number <> DPERR_ALREADYINITIALIZED Then
  88.     MsgBox ("Failed to initialize connection.")
  89.     Exit Sub
  90.   End If
  91. End Sub
  92. Private Sub Form_Load()
  93.   ' Enumerate connections
  94.   If Not InitConnectionList Then
  95.     Call MsgBox("Failed to Enumerate Connections.")
  96.     CloseDownDPlay
  97.     End
  98.   End If
  99. End Sub
  100. Private Sub Form_Unload(Cancel As Integer)
  101.   'frmMainMenu.Show
  102. End Sub
  103. Private Sub lstConnections_DblClick()
  104.     cmdOK_Click
  105. End Sub
  106. ' Highlight player name when selected
  107. Private Sub txtYourName_GotFocus()
  108.   'txtYourName.SelStart = 0
  109.   'txtYourName.SelLength = txtYourName.MaxLength
  110. End Sub
  111. ' Enumerate connections
  112. Public Function InitConnectionList() As Boolean
  113.   Dim NumConnections As Long
  114.   Dim strName As String
  115.   Dim x As Long
  116.   Call InitDPlay     ' Program aborts on failure
  117.   connectiontype.Clear
  118.   On Error GoTo FAILED
  119.   NumConnections = EnumConnections.GetCount
  120.   For x = 1 To NumConnections
  121.     strName = EnumConnections.GetName(x)
  122.     Call connectiontype.AddItem(strName)
  123.   Next x
  124.   ' Initialize selection
  125.   connectiontype.ListIndex = 0
  126.   InitConnectionList = True
  127.   Exit Function
  128.   ' Error handlers
  129. FAILED:
  130.   InitConnectionList = False
  131.   Exit Function
  132. End Function
  133.